package com.example.flower_shop.service.usr.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.example.flower_shop.mapper.RoleMapper;
import com.example.flower_shop.service.usr.AuthService;
import com.example.flower_shop.vo.role.RoleRespVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthServiceImpl implements AuthService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public List<String> getPerm() {
        return roleMapper.selectRoleByUserId(getUserId()).stream().map(RoleRespVO::getName).toList();
    }

    @Override
    public List<String> getRoles() {
        return roleMapper.selectRoleByUserId(getUserId()).stream().map(RoleRespVO::getName).toList();
    }

    @Override
    public List<String> getRolesByUserId(Object userId) {
        return roleMapper.selectRolesByUserId(userId);
    }

    private Long getUserId() {
        return StpUtil.getLoginIdAsLong();
    }
}
